unit uWorldBase.local;

interface

uses Classes,

     uTyres.local,
     uEngines.local,
     uChassis.local,
     uTeams.local,
     uDriver.local,
     uTrack.local;

type
  //================================ WORLDBASE
  TWorldBase = class( TObject )
  public
    TyreList    : TTyreList;
    EngineList  : TEngineList;
    ChassisList : TChassisList;
    TeamList    : TTeamList;
    DriverList  : TDriverList;
    TrackList   : TTrackList;

    constructor Create;
    destructor Destroy; override;

    function Import(FileName:string):boolean;

  end;

implementation

uses Math, SysUtils,

     uFuncs.common, uDebug.common, uSplitter.common;


  //================================ WORLDBASE
constructor TWorldBase.Create;
begin
  inherited Create;

  TyreList    := TTyreList.Create;
  EngineList  := TEngineList.Create;
  ChassisList := TChassisList.Create;
  TeamList    := TTeamList.Create;
  DriverList  := TDriverList.Create;
  TrackList   := TTrackList.Create;
end;
destructor TWorldBase.Destroy;
begin
  FreeAndNil( TyreList   );
  FreeAndNil( EngineList );
  FreeAndNil( ChassisList );
  FreeAndNil( TeamList   );
  FreeAndNil( DriverList );
  FreeAndNil( TrackList  );

  inherited Destroy;
end;
function TWorldBase.Import(FileName:string):boolean;
var Splitter : TSplitter;
begin
  result := FALSE;

  FileName := GetEXEPath + FileName;

  Splitter := TSplitter.Create;

  if ( Splitter.LoadFile( FileName ) ) then
  begin
    result := TRUE;

    with Splitter do
    while GetNextLine() do
    begin
//      DevConsole.Msg(ES_DEBUG, '('+IntToStr(Splitter.Words.Count)+') # '+NextLine);

      if (To_Str(0) = 'TYRE'    ) then TyreList.Add   ( To_Int(1), To_Str(2), To_Int(3), To_Int(4)) else
      if (To_Str(0) = 'ENGINE'  ) then EngineList.Add ( To_Int(1), To_Str(2), To_Int(3), To_Int(4)) else
      if (To_Str(0) = 'CHASSIS' ) then ChassisList.Add( To_Int(1), To_Str(2), To_Int(3)) else
      if (To_Str(0) = 'TEAM'    ) then TeamList.Add   ( To_Int(1), To_Str(2), To_Int(3), To_Int(4)) else
      if (To_Str(0) = 'DRIVER'  ) then DriverList.Add ( To_Int(1), To_Str(2), To_Str(3), To_Int(4), To_Int(5), To_Int(6), To_Int(7) );
      if (To_Str(0) = 'TRACK'   ) then TrackList.Add  ( To_Int(1), To_Str(2), To_Str(3), To_Int(4), To_Int(5), To_Float(6), To_Int(7), To_Int(7) );
    end;
  end;
end;

end.
